from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
from . import service
# Create your views here.

def index(request):
    ts = service.getAllTitles()
    return render(request, "poem/list.html",{"titles":ts})

def detail(request, name):
    poem = service.getPoemByTitle(name)
    return render(request, 'poem/shige.html', {"shi":poem})

def create(request):
    return render(request, 'poem/create.html',{})


def chuangjiang(request):
    # 获取表单传来的数据 
    title = request.POST['aa']
    content = request.POST['neirong']
    # 数据保存到数据库
    service.addPoem(title, content)
    # 跳转到列表页面
    return HttpResponseRedirect( reverse('poem:index'))
    